<template>
	<Table ref="tableRef" :url="URL_QUERYRECORDLIST" :columns="data.columns" :toolbar="data.toolbar"
		:query="data.query" :params="{ unit: true }" listKey="dataList"></Table>
</template>

<script lang="ts" setup name="afterSalesRecordList">
	import Table from '@/components/table/index.vue';
	import {
		URL_QUERYRECORDLIST
	} from '@/service/apis/user';
	import { exportFile } from '@/utils/utils';
	const router = useRouter();
	const tableRef = ref();

	const emit = defineEmits(['get-update']);
	onActivated(() => {
		emit('get-update', (flag : boolean) => {
			if (flag) {
				tableRef.value?.getData();
			}
		});
	});

	const data = reactive({
		pickDate: null as any,
		columns: [
			{
				prop: 'name',
				label: '姓名',
			},
			{
				prop: 'mobile',
				label: '手机号',
			},
			{
				prop: 'createTime',
				label: '申请时间',
			},
			{
				prop: 'equipmentCode',
				label: '电桩编码',
			},
			{
				prop: 'factoryNumber',
				label: '出厂编号',
			},
			{
				prop: 'authCode',
				label: '授权码',
			},
		],
		toolbar: [
			// {
			// 	label: '导出',
			// 	permission: 'noEnterpriseUserList.export',
			// 	icon: 'icon-export',
			// 	type: 'primary',
			// 	plain: true,
			// 	handle: (row : any) => {
			// 		console.log('导出---', row);
			// 		exportFile(EXPORT_USER, '非企业用户列表', tableRef.value?.getForm());
			// 	},
			// },
		],
		query: [
			{
				label: '姓名',
				prop: 'name',
				comName: 'input',
				props: {
					placeholder: '请输入用户姓名',
				},
			},
			{
				label: '手机号',
				prop: 'mobile',
				comName: 'input',
				props: {
					placeholder: '请输入手机号',
				},
			},
			{
				label: '电桩编码',
				prop: 'equipmentCode',
				comName: 'input',
				props: {
					placeholder: '请输入电桩编码',
				},
			},
			{
				label: '出厂编号',
				prop: 'factoryNumber',
				comName: 'input',
				props: {
					placeholder: '请输入出厂编号',
				},
			},
			{
				label: '申请时间',
				prop: 'startData',
				comName: 'date',
				keys: ['createTimeBegin', 'createTimeEnd'],
				props: {
					type: 'daterange',
					calendarChange: (pick : any) => {
						let hasSelectDate = pick !== null && pick.length > 0;
						data.pickDate = hasSelectDate ? pick[0] : null;
					},
					change: (time : any) => {
						if (!time) {
							data.pickDate = null;
						}
					},
					disabledDate: (time : any) : any => {
						if (data.pickDate) {
							const checkTime = data.pickDate.getTime();
							const startTime = checkTime - 62 * 86400 * 1000; // 前面限制62天
							const endTime = checkTime + 62 * 86400 * 1000; // 后面限制62天
							return time.getTime() > endTime || time.getTime() < startTime;
						} else {
							return false;
						}
					},
				},
			},
		],
	});
</script>